from django.db import models


class UserGroup(models.Model):
    title = models.CharField(max_length=32)
    created_at = models.DateTimeField(auto_now_add=True)


class Role(models.Model):
    title = models.CharField(max_length=64)
    created_at = models.DateTimeField(auto_now_add=True)


from rest_framework import  serializers
class RoleSerializer(serializers.Serializer):
    title = serializers.CharField()
    created_at = serializers.DateTimeField()


# Create your models here.
class UserInfo(models.Model):
    user_types_choice = (
        (1, '普通用户'),
        (2, 'VIP'),
        (3, 'SVIP'),
    )
    # 字段名不能使用python关键字
    id = models.AutoField(primary_key=True)
    user_type = models.IntegerField(choices=user_types_choice)
    username = models.CharField(max_length=20, unique=True)
    password = models.CharField(max_length=128)
    created_at = models.DateTimeField(auto_now_add=True)

    group = models.ForeignKey(UserGroup, on_delete=models.CASCADE)
    roles = models.ManyToManyField(Role)


class UserToken(models.Model):
    user = models.OneToOneField(to=UserInfo, on_delete=models.CASCADE)
    token = models.CharField(max_length=64)
